#!/usr/bin/env python
# -*- coding:utf-8 -*-

# file:4_student_login.py
# author:张世航
# datetime:2024/11/9 22:29
# software: PyCharm
"""
this is function  description 
"""
# import module your need


# 4  (继续上面的练习) 模拟用户登录:
#      5个同学的姓名,账号和密码(加密后的),保存在一个文件上;
#      系统提示,请输入登录同学姓名, 正确后,请输入账号, 正确后,提示请输入密码（输入明文）;  如果都正确,打印提示, 您登录成功(失败);

import hashlib

def encrypt_password(password):
    """简单的密码加密"""
    return hashlib.sha256(password.encode()).hexdigest()

def login():
    name = input("请输入登录同学姓名: ")
    account = input("请输入账号: ")
    password = input("请输入密码: ")

    try:
        with open("students.txt", "r", encoding="utf-8") as f:
            for line in f:
                stored_name, stored_account, stored_password = line.strip().split()
                if stored_name == name and stored_account == account:
                    if stored_password == encrypt_password(password):
                        print("您登录成功！")
                        return
        print("登录失败！")
    except FileNotFoundError:
        print("学生信息文件未找到，请确保文件存在。")

# 主程序
if __name__ == "__main__":
    login()